
class DateUtils{
    static isCurrentDay(timestamp){
        let date = DateUtils.formatDate(timestamp);
        let currentDate = new Date()
        return date.toLocaleDateString() == currentDate.toLocaleDateString()
    }
    static getDaysBetweenDates(date1, date2) {
        date1 = DateUtils.formatDate(date1);

        date2 = DateUtils.formatDate(date2);
        // 获取时间戳（毫秒）
        let timestamp1 = date1.getTime();
        let timestamp2 = date2.getTime();
        // 计算时间差（毫秒）
        let diff = Math.abs(timestamp2 - timestamp1);
        // 将时间差转换为天数
        return Math.floor(diff / (1000 * 60 * 60 * 24))
    }

    static formatDate(date){
        if(typeof date === "number"){
            if((""+date).length < 12){
                date = parseInt(date)*1000
            }
            date = new Date(date);
        }
        else if(typeof date === "string"){
            // 将日期字符串转换为日期对象
            date = new Date(date);
        }
        return date
    }
    //date2 - date1 在 num 天之内
    static dateDiffWithNumber(date1, date2, num){
       return DateUtils.getDaysBetweenDates(date1,date2) < num
    }

    static diifTime(timestamp1){
        timestamp1 = DateUtils.formatDate(timestamp1)
        let timestamp2 = new Date()
        return timestamp1.getTime() - timestamp2.getTime()
    }
}

module.exports = DateUtils